//
//  FeedBackViewController.m
//  SsehMaster
//
//  Created by yang yang on 2018/8/15.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "FeedBackViewController.h"

@interface FeedBackViewController ()<UITextViewDelegate>

@property (nonatomic,strong) UITextView *textView;

@property (nonatomic,strong) UILabel * numLabel;

@end

@implementation FeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"意见反馈";
    self.view.backgroundColor = [UIColor whiteColor];
    [self layoutUI];
}



-(void)layoutUI{
    __weak typeof (self)weakSelf = self;
    UIView * bgView = [UIView new];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).offset(NAVIGATION_BAR_HEIGHT+60);
        make.centerX.equalTo(weakSelf.view.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(F_DEVICE_W-40, 300));
    }];
    
    self.textView = [[UITextView alloc]init];
    self.textView.delegate = self;
    self.textView.layer.borderWidth = 1.0f;
    self.textView.layer.borderColor = RGBColor(178, 178, 178).CGColor;
    self.textView.layer.cornerRadius = 5;
    self.textView.font = [UIFont systemFontOfSize:14];
    
    [bgView addSubview:self.textView];
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    UILabel *placeHolderLabel = [UILabel new];
    placeHolderLabel.font = self.textView.font;
    placeHolderLabel.text = @"在这里写下您宝贵的意见吧";
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.textColor = [UIColor lightGrayColor];
    [placeHolderLabel sizeToFit];
    [self.textView addSubview:placeHolderLabel];
    [self.textView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
    
    self.numLabel = [UILabel new];
    self.numLabel.font = [UIFont systemFontOfSize:14];
    self.numLabel.textColor = [UIColor lightGrayColor];
    self.numLabel.text = @"字数限制 (0/600)";
    self.numLabel.textAlignment = NSTextAlignmentRight;
    [bgView addSubview:self.numLabel];
    [bgView bringSubviewToFront:self.numLabel];
    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bgView).offset(-10);
        make.bottom.equalTo(bgView);
    }];
    
    UIButton * sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
    sureButton.titleLabel.font = [UIFont systemFontOfSize:16];
    sureButton.layer.cornerRadius = 5;
    [sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sureButton setTitle:@"提交" forState:UIControlStateNormal];
    [sureButton setBackgroundColor:RGBColor(51, 51, 51)];
    [sureButton addTarget:self action:@selector(sureButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:sureButton];
 
    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(bgView.mas_leading);
        make.trailing.equalTo(bgView.mas_trailing);
        make.top.equalTo(bgView.mas_bottom).offset(50);
        make.height.mas_equalTo(50);
    }];
    
}

-(void)sureButtonClick:(UIButton *)button{
    
    if (k_Is_Empty(self.textView.text)) {
        return;
    }
    
    
}

- (void)textViewDidChange:(UITextView *)textView{
    self.numLabel.text = [NSString stringWithFormat:@"字数限制 (%ld/600)",textView.text.length];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
